package com.guijie.sheji.controller;

import com.github.pagehelper.Page;
import com.guijie.sheji.common.MessageConstant;
import com.guijie.sheji.common.PageResult;
import com.guijie.sheji.common.Result;
import com.guijie.sheji.common.StatusCode;
import com.guijie.sheji.domain.Admin;
import com.guijie.sheji.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/*
* 管理员控制层
* */
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @RequestMapping("/find")
    public Result find(){
        List<Admin> all = adminService.findAll();
        return new Result(false,200,"请求成功",all);
    }
    @RequestMapping("/search")
    public PageResult search(@RequestBody Map searchMap){
        Page<Admin> page = adminService.search(searchMap);
        return new PageResult(true, StatusCode.OK, MessageConstant.ADMIN_SEARCH_SUCCESS,page.getResult(),page.getTotal());
    }
    @RequestMapping("/findById")
    public Result findById(Integer id){
        Admin admin = adminService.findById(id);
        return new Result(true,StatusCode.OK,MessageConstant.ADMIN_FIND_BY_ID_SUCCESS,admin);
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Admin admin){
        Boolean add = adminService.update(admin);
        return new Result(true,StatusCode.OK,MessageConstant.ADMIN_UPDATE_SUCCESS);
    }

    @RequestMapping("/del")
    public Result del(@RequestBody List<Integer> ids){
        Boolean flag = adminService.del(ids);
        return new Result(true,StatusCode.OK,MessageConstant.ADMIN_DELETE_SUCCESS);
    }
}
